<template>
  <div>
    <div class="row-header">
      <el-form :model="form" :rules="formRules" :inline="true" label-width="150px">
        <el-form-item label="失败开始时间">
          <el-date-picker class="select" v-model="form.startTime" type="datetime" align="right" placeholder="失败开始时间"
                          style="width: 300px;" value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
        </el-form-item>
        <el-form-item label="失败结束时间">
          <el-date-picker class="select" v-model="form.endTime" type="datetime" align="right" placeholder="失败结束时间"
                          style="width: 300px;" value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
        </el-form-item>
        <el-form-item label="msisdn" prop="cardMsisdn">
          <el-input size="small" v-model.trim="form.cardMsisdn" style="width: 300px;"></el-input>
        </el-form-item>
        <el-form-item label="imsi" prop="cardImsi">
          <el-input size="small" v-model.trim="form.cardImsi" style="width: 300px;"></el-input>
        </el-form-item>
        <el-form-item label="iccid" prop="iccid">
          <el-input style="width: 300px;" v-model.trim="form.iccid"></el-input>
        </el-form-item>
      </el-form>
      <div class="row-form-btn">
        <el-button type="shenda" size="small" icon="el-icon-search" @click="currentPage = 1 ; initData()">查询</el-button>
      </div>
    </div>
    <div class="split-line"></div>
    <div class="row-main">
      <el-table :header-cell-style="{ 'background':$store.state.app.tableBgColor,'color':'#606266' }" :data="tableData"
                tooltip-effect="dark" class="row-main-table" @selection-change="handleSelectionChange"
                v-loading.fullscreen="tableLoading" element-loading-text="拼命加载中"
                element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.2)">
        <el-table-column type="selection" align="center"></el-table-column>
        <el-table-column prop="failedInfo" label="失败信息" align="center"></el-table-column>
        <el-table-column prop="failCode" label="失败码" align="center"></el-table-column>
        <el-table-column prop="startTime" label="失败开始时间" align="center"></el-table-column>
        <el-table-column prop="endTime" label="失败结束时间" align="center"></el-table-column>
        <el-table-column prop="cardMsisdn" label="msisdn" align="center"></el-table-column>
        <el-table-column prop="cardImsi" label="imsi" align="center"></el-table-column>
        <el-table-column prop="iccid" label="iccid" align="center"></el-table-column>
        <el-table-column prop="insertTime" label="失败时间" align="center"></el-table-column>
      </el-table>
      <div class="block"><span class="demonstration"></span>
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" class="row-main-pager"
                       :current-page.sync="currentPage" :page-size="pageSize" layout="total,sizes,prev, pager, next, jumper"
                       :total="total" :page-sizes="[10,20,50,100]" background></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import {taskFail} from '@/api/getData'

export default {
  name: 'ExceptionMessage',
  data() {
    const validateTaskId = (rule, value, callback) => {
      if (value.length > 20) {
        callback(new Error('任务ID不能超过20位'))
      } else {
        callback()
      }
    }
    const validateCardMsisdn = (rule, value, callback) => {
      if (value.length > 50) {
        callback(new Error('msisdn不能超过50位'))
      } else {
        callback()
      }
    }
    const validateCardImsi = (rule, value, callback) => {
      if (value.length > 50) {
        callback(new Error('imsi不能超过50位'))
      } else {
        callback()
      }
    }
    const validateIccid = (rule, value, callback) => {
      if (value.length > 50) {
        callback(new Error('iccid不能超过50位'))
      } else {
        callback()
      }
    }
    return {
      maxPage: 1,
      tableData: [],
      total: 0,
      pageSize: 10,
      currentPage: 1,
      tableLoading: false,
      value: false,
      taskId: '',
      cardMsisdn: '',
      cardImsi: '',
      iccid: '',
      failedInfo: '',
      failCode: '',
      insertTime: '',
      startTime: '',
      endTime: '',
      form: {
        taskId: '',
        cardMsisdn: '',
        cardImsi: '',
        iccid: '',
        startTime: '',
        endTime: ''
      },
      formRules: {
        taskId: [
          {validator: validateTaskId, trigger: 'blur'}
        ],
        cardMsisdn: [
          {validator: validateCardMsisdn, trigger: 'blur'}
        ],
        cardImsi: [
          {validator: validateCardImsi, trigger: 'blur'}
        ],
        iccid: [
          {validator: validateIccid, trigger: 'blur'}
        ]
      }
    }
  },
  created() {
    this.initData()
  },
  methods: {
    async initData() {
      const returnData = await taskFail({
          taskId: this.form.taskId,
          cardMsisdn: this.form.cardMsisdn,
          cardImsi: this.form.cardImsi,
          iccid: this.form.iccid,
          startTime: this.form.startTime,
          endTime: this.form.endTime,
          page: {
            current: this.currentPage + '',
            size: this.pageSize + '',
            ascs: this.ascs,
            descs: this.descs
          }
        },
        {
          obj: this,
          key: 'tableLoading'
        })
      this.tableData = [];
      this.total = 0;
      if (returnData._result) {
        this.maxPage = Math.ceil(returnData.data.total / this.pageSize) // 分页的最大页数
        returnData.data.records.map(item => {
          const obj = {}
          obj.taskId = item.taskId // 任务id
          obj.failedInfo = item.failedInfo // 失败信息
          obj.failCode = item.failCode // 失败码
          obj.cardMsisdn = item.cardMsisdn // msisdn
          obj.cardImsi = item.cardImsi // imsi
          obj.iccid = item.iccid // iccid
          obj.insertTime = item.insertTime // 失败时间
          obj.startTime = item.startTime // iccid
          obj.endTime = item.endTime // 失败时间
          this.tableData.push(obj)
        })
        this.total = returnData.data.total;
        this.tableLoading = false
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    handleSizeChange(val) {
     this.currentPage = 1;
      this.pageSize = val;
      this.initData();
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.initData()
    },
  }
}
</script>

<style scoped lang="scss">

.examine /deep/ .el-dialog__body {
  text-align: center;
  font-size: 14px;
  font-family: 微软雅黑;
  line-height: 40px;
  color: #606266;
  font-weight: 700;
}

.el-popper[x-placement^=bottom] {
  margin-right: -25px;
  box-shadow: 0px 0px 10px #888888;
  margin-left: 6px;

  .operation {
    border: 0;
    outline: none;
    display: block;
    text-align: center;
    margin: 0;
  }
}

.el-popper[x-placement^=top] {
  box-shadow: 0px 0px 10px #888888;
  margin-left: 6px;
  margin-right: -25px;

  button {
    display: block;
  }

  .operation {
    border: 0;
    outline: none;
    display: block;
    text-align: center;
    margin: 0;
  }
}
</style>
